//    Copyright (C) Kherty.  All rights reserved.
using System;

namespace OpenLS.Spreadsheet.AnalysisToolPak
{
    internal class European360Basis : ConstantDateBasis
    {
        protected override int DaysInYearImp
        {
            get { return 360; }
        }

        protected override DateBasisType Type
        {
            get { return DateBasisType.European360; }
        }

        internal override int DaysBetweenImp(DateTime start, DateTime end)
        {
            int y1, m1, d1, y2, m2, d2;
            y1 = start.Year;
            m1 = start.Month;
            d1 = start.Day;
            y2 = end.Year;
            m2 = end.Month;
            d2 = end.Day;
            if (d1 == 31)
                d1 = 30;
            if (d2 == 31)
                d2 = 30;
            return (y2 - y1)*360 + (m2 - m1)*30 + (d2 - d1);
        }

        protected override int DayDifferenceImp(DateTime d1, DateTime d2)
        {
            int months = (d1.Year - d2.Year)*12 + (d1.Month - d2.Month);
            return months*30 + (d1.Day - d2.Day);
        }

        internal virtual double CoupDaysNc(DateTime settlement, DateTime maturity, Frequency frequency)
        {
            throw new NotImplementedException();
        }

        protected virtual int DaysBetweenImpOld(DateTime start, DateTime end)
        {
            return (end.Year - start.Year) * 360 + (end.Month - start.Month) * 30 + (Math.Min(end.Day, 30) - Math.Min(start.Day, 0));

        }
    }
}